<?php

namespace apiend\modules\attach\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\attach\models\AlbumSearch;
use apiend\modules\attach\models\AlbumPictureSearch;
use apiend\modules\attach\models\AlbumPictureUploadForm;

/**
 * 商城附件相册接口
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class AlbumController extends Controller {

    /**
     * @inheritdoc
     */
    public $modelClass = AlbumSearch::class;

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
            'upload' => ['POST'],
        ];
    }

    /**
     * 聚合标签检索接口
     * @inheritdoc
     */
    public function actionIndex() {
        /* @var $model AlbumSearch */
        $model = new $this->modelClass;
        $model->load(Yii::$app->request->getQueryParams(), '');
        $model->store_id = $this->storeId;
        return $model->search();
    }

    /**
     * 聚合标签检索接口
     * @inheritdoc
     */
    public function actionView($id) {
        return $this->findModel($id);
    }

    /**
     * 聚合标签检索接口
     * @inheritdoc
     */
    public function actionPictures($id = 0) {
        $model = new AlbumPictureSearch();
        $model->album_id = $id;
        $model->store_id = $this->storeId;
        $model->load(Yii::$app->request->getQueryParams(), '');
        return $model->search();
    }

    /**
     * 聚合标签检索接口
     * @inheritdoc
     */
    public function actionUpload() {
        $model = new AlbumPictureUploadForm();
        $model->load(Yii::$app->request->post(), '');
        $model->store_id = $this->storeId;
        return $model->save();
    }

}
